@extends('shop::layouts.master')
@section('title')
    订单详情
@endsection
<style>
    .ordertab1{border-top:1px solid #e6e6e6;border-left:1px solid #e6e6e6;font-size: 12px; margin-bottom: 80px}
    .ordertab1 td{border-right:1px solid #e6e6e6;border-bottom:1px solid #e6e6e6;}
    .orderbg{height:33px;line-height:33px;background:#e6e6e6;text-align:center;border-bottom:1px solid #d5d5d5;}
</style>
@section('tab')
    <div style="padding: 20px; background-color: #F2F2F2; ">
        <div class="layui-row layui-col-space15">

            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">订单信息</div>
                    <div class="layui-card-body" style="overflow-y: hidden;" id="order_info">
                        订单状态：{{$info['order_state']}} <br>
                        订单编号：{{$info['order_no']}} <br>
                        商品总数：{{$info['goods_num']}} （件）<br>
                        下单时间：{{$info['created_at']}} <br>
                        @if($info['pay_status'] == 2)
                            支付方式：积分兑换 <br>
                            支付时间：{{$info['pay_time']}} <br>
                        @endif

                        @if($info['status'] > 1 && $info['status'] != 5)
                            快递公司：@foreach($info['xpress'] as $k => $v) @if($info['xpress_id'] == $v['id']) {{$v['name']}} @endif @endforeach<br>
                            快递单号：{{$info['delivery_no']}} <br>
                            发货时间：{{$info['delivery_time']}} <br>
                        @endif

                        @if($info['delivery_status'] == 3)
                            收货时间：{{$info['receiving_time']}} <br>
                        @endif

                        @if(!empty($info['cancel_reason']) && $info['status'] == 5)
                            取消原因：{{$info['cancel_reason']['reason']}} <br>
                            取消时间：{{$info['cancel_time']}}
                        @endif
                    </div>
                </div>
            </div>

            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">买家信息</div>
                    <div class="layui-card-body" style="overflow-y: hidden;">
                        买家真实姓名：{{$info['get_user_info']['realname']}} <br>
                        买家电话：{{$info['get_user_info']['phone']}} <br>
                        买家邮箱：{{$info['get_user_info']['email']}} <br>
                        收货人名称：{{$info['get_address_info']['username']}} <br>
                        收货人电话：{{$info['get_address_info']['phone']}} <br>
                        收货地址：{{$info['get_address_info']['province']}} - {{$info['get_address_info']['city']}} - {{$info['get_address_info']['area']}}<br>
                        详细地址：{{$info['get_address_info']['address']}} <br>
                    </div>
                </div>
            </div>

            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">商品清单</div>
                    <div class="layui-card-body" style="overflow-y: hidden;">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ordertab1">
                            <tr class="orderbg">
                                <td height="36" colspan="2">商品</td>
                                <td height="36">规格</td>
                                <td width="150">单价 x 数量</td>
                                <td width="150">费用明细（积分）</td>
                                @if($info['remark'])
                                    <td width="100">订单备注</td>
                                @endif
                            </tr>
                                <tr align="center">
                                    <td width="100" height="115"><p class="proimg">
                                         <img src="{{$info['product_info']['pic']['full_src']}}" width="100"height="100"/></p>
                                    </td>
                                    <td width="300" style="padding: 10px;line-height:20px;">{{$info['get_goods_info']['name']}}</td>
                                    <td width="120" style="padding: 10px;line-height:20px;">{{$info['product_info']['specs']['name']}}</td>
                                    <td>{{$info['goods_integral']}} x {{$info['goods_num']}}</td>

                                    <td style="line-height:20px">
                                        <p>商品总积分：{{$info['order_integral']}}</p>
                                    </td>
                                    @if($info['remark'])
                                        <td><p>{{$info['remark']}}</p></td>
                                    @endif
                                </tr>

                            <tr align="center">
                                <td colspan="9" style="padding: 20px">
                                    @if($info['status'] == 1 && $info['pay_status'] == 2)
                                        <div class="layui-input-inline">
                                            <select name="xpress_id" style="height: 30px;width: 175px" id="xpress_id">
                                                <option value="">请选择快递公司</option>
                                                @if($info['xpress'])
                                                    @foreach($info['xpress'] as $k => $v)
                                                        <option value="{{$v['id']}}">{{$v['name']}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <input type="text" name="delivery_no" value="" id="delivery_no" placeholder="请输入快递单号"  class="layui-input">
                                        </div>
                                        <div class="layui-input-inline" style="text-align: center">
                                            <a title="确认发货" class="layui-btn layui-btn-normal state-btn" data-title="确认发货吗？"
                                               data-id="{{$info['id']}}" data-type='1' href="javascript:;">确认发货
                                            </a>
                                        </div>
                                    @endif

                                    @if($info['status'] == 1 && $info['pay_status'] == 1)
                                        <a title="取消订单" class="layui-btn layui-btn-war state-btn" data-title="确认取消订单吗？"
                                           data-id="{{$info['id']}}" data-type='2' data-status='5' href="javascript:;">取消订单
                                        </a>
                                    @endif
                                    @if($info['status'] > 1 && $info['status'] != 5 && $info['status'] != 6 && $info['status'] != 7 && $info['pay_status'] == 2)
                                        <a onclick="xadmin.open('查看物流','{{route("shop_logistics_tracking",["id"=>$info["id"],"type"=>1])}}')"
                                           title="查看物流" class="layui-btn">查看物流
                                        </a>
                                    @endif
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>

        </div>
    </div>

@endsection

@section('tab_js')
    <script>
        $(document).on('click', '.state-btn', function () {
            var that = $(this);
            var id = that.data('id');
            var type = that.data('type');
            var data = {};
            var url = "";
            if(type == 1){
                var xpress_id = $('#xpress_id').val();     //快递公司id
                var delivery_no = $('#delivery_no').val(); //快递单号
                if(!xpress_id){
                    layer.msg('请选择快递公司', {time: 2000, icon: 5});
                    return false;
                }
                if(!delivery_no){
                    layer.msg('请输入快递单号', {time: 2000, icon: 5});
                    return false;
                }
                url = "shop-order-deliver-goods";
                data = {id: id, xpress_id: xpress_id, delivery_no: delivery_no};
            }
            if(type == 2){
                var status = that.data('status');
                url = "shop-order-chang-status";
                data = {id: id, status: status};
            }

            layer.confirm(that.data('title'), {btn: ['确定', '取消']}, function () {
                $.ajax({
                        url: url,
                        type: 'post',
                        dataType: "json",
                        data: data,
                        success: function (result) {
                            if (result.state === 0) {
                                layer.msg('设置成功', {icon: 1, time: 1000}, function () {
                                    location_refresh();
                                });
                            } else {
                                layer.msg(result.msg, {time: 2000, icon: 5});
                            }
                        }
                    }
                );
            });
        });
    </script>

@endsection